package com.chd.ledger_server.service.impl;

import com.chd.ledger_server.entity.DevDevices;
import com.chd.ledger_server.dao.DevDevicesDao;
import com.chd.ledger_server.service.DevDevicesService;
import com.chd.ledger_server.domain.PageDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备表(DevDevices)表服务实现类
 *
 * @author makejava
 * @since 2025-07-20 17:37:41
 */
@Service("devDevicesService")
public class DevDevicesServiceImpl implements DevDevicesService {
    @Resource
    private DevDevicesDao devDevicesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param deviceId 主键
     * @return 实例对象
     */
    @Override
    public DevDevices queryById(Integer deviceId) {
        return this.devDevicesDao.queryById(deviceId);
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo queryAllDevDevicessByPage(PageDto pageDto) {
        //空值处理
        if (pageDto.getPage() == null || pageDto.getSize() == null) {
            pageDto.setPage(1);
            pageDto.setSize(10);
        }
        PageHelper.startPage(pageDto.getPage(), pageDto.getSize());
        List<DevDevices> list = devDevicesDao.queryAll(pageDto.getDevDevices());
        PageInfo<DevDevices> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param devDevices 实例对象
     * @return 实例对象
     */
    @Override
    public DevDevices insert(DevDevices devDevices) {
        this.devDevicesDao.insert(devDevices);
        return devDevices;
    }

    /**
     * 修改数据
     *
     * @param devDevices 实例对象
     * @return 实例对象
     */
    @Override
    public DevDevices update(DevDevices devDevices) {
        this.devDevicesDao.update(devDevices);
        return this.queryById(devDevices.getDeviceId());
    }

    /**
     * 通过主键删除数据
     *
     * @param deviceId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer deviceId) {
        return this.devDevicesDao.deleteById(deviceId) > 0;
    }
}
